﻿#pragma once

#include "ff_utils.h"
#include <tchar.h>
#include <windows.h>
#include <windowsx.h>

namespace feifei
{
#define wINFO(fmt,...)		wPrintInfo(fmt,##__VA_ARGS__)
#define	wLOG(fmt,...)		wPrintLog(fmt,##__VA_ARGS__)
	void wPrintInfo(const char* format, ...);
	void wPrintInfo(std::string msg, ...);
	void wPrintLog(const char* format, ...);
	void wPrintLog(std::string msg, ...);

	class WinAppBase
	{
	protected:
		WinAppBase(HINSTANCE hInstance);

	public:
		static WinAppBase* GetApp();

		virtual LRESULT MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
		virtual bool Init(std::wstring caption = L"Window", int width = 800, int height = 600);
		int Run();
		HWND GetWinHandle() { return mhMainWnd; }
		int GetWinWidth() { return mClientWidth; }
		int GetWinHeight() { return mClientHeight; }
		void SetRunFunc(void(*ptr)()) { mRunFuncPtr = ptr; }

	protected:
		static WinAppBase* gWinApp;
		HINSTANCE mhAppInst = nullptr; // application instance handle
		HWND      mhMainWnd = nullptr; // main window handle

		std::wstring mMainWndCaption;
		int mClientWidth;
		int mClientHeight;

		virtual void OnMouseDown(WPARAM btnState, int x, int y) { }
		virtual void OnMouseUp(WPARAM btnState, int x, int y) { }
		virtual void OnMouseMove(WPARAM btnState, int x, int y) { }
		void (*mRunFuncPtr)();
	};


	class WindowBase
	{
	public:
		WindowBase(std::string title, int width, int height)
			:m_winTitle((LPCTSTR)title.c_str())
			, m_width(width), m_height(height)
		{
		}

		void CreateMainWindow();

		// the WindowProc function prototype
		static LRESULT CALLBACK WindowProc(HWND hWnd,
			UINT message,
			WPARAM wParam,
			LPARAM lParam);
	protected:
		HWND m_hWnd;
		LPCTSTR m_winTitle;
		int m_width;
		int m_height;
	
	};
} // end namespace feifei
